from manim import *



class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
          #文本
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)

        text = Tex(
                    r"\text{二阶偏导计算秘籍}",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,25,0])
        #2框框标
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=21,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([0,25,0])

        self.play(Write(text),Create(rectangle))

        #箭头引出
        arrow = Arrow(start=[0,20,0],end=[0,15,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow))

        text1 = Tex(
                    r"$\dfrac{\partial z}{\partial x}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,12,0])
        #2框框标
        rectangle1=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=GREEN,stroke_width=20)
        rectangle1.move_to([-20,12,0])

        text2 = Tex(
                    r"$\dfrac{\partial z}{\partial y}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,12,0])
        #2框框标
        rectangle2=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=GREEN,stroke_width=20)
        rectangle2.move_to([20,12,0])

        self.play(Write(text1),Create(rectangle1),Write(text2),Create(rectangle2))

         #箭头引出
        arrow1 = Arrow(start=[0,10,0],end=[0,5,0], color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow1))
        #情形111111
        text3 = Tex(
                    r"$\dfrac{\partial ^{2}z}{\partial x^{2}}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-3,0])
        #2框框标
        rectangle3=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle3.move_to([-30,-3,0])

        text4 = Tex(
                    r"$\dfrac{\partial ^{2}z}{\partial y^{2}}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,-3,0])
        #2框框标
        rectangle4=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle4.move_to([30,-3,0])


        text5 = Tex(
                    r"$\dfrac{\partial ^{2}z}{\partial x\partial y}$",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-3,0])
        #2框框标
        rectangle5=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=YELLOW,stroke_width=20)
        rectangle5.move_to([0,-3,0])

        self.play(Write(text3),Create(rectangle3),Write(text4),Create(rectangle4),Write(text5),Create(rectangle5))


        #情形22222

        text6 = Tex(
                    r"$ \dfrac{\partial ^{2}z}{\partial x^{2}}| \left( x_{0},y_{0}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-30,-17,0])
        #2框框标
        rectangle6=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=RED,stroke_width=20)
        rectangle6.move_to([-30,-17,0])

        text7 = Tex(
                    r"$ \dfrac{\partial ^{2}z}{\partial y^{2}}| \left( x_{0},y_{0}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([30,-17,0])
        #2框框标
        rectangle7=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=RED,stroke_width=20)
        rectangle7.move_to([30,-17,0])


        text8 = Tex(
                    r"$ \dfrac{\partial ^{2}z}{\partial x\partial y}| \left( x_{0},y_{0}\right) $",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-17,0])
        #2框框标
        rectangle8=Rectangle(color=GREEN,fill_opacity=0.0,width=18,height=6
                            ,stroke_color=RED,stroke_width=20)
        rectangle8.move_to([0,-17,0])

        self.play(Write(text6),Create(rectangle6),Write(text7),Create(rectangle7),Write(text8),Create(rectangle8))

        self.play(self.camera.frame.animate.scale(0.8).move_to([-20,12,0]))
        text9 = Tex(
                    r"\text{硬算}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle1,UP,buff=1)
        self.play(Write(text9))
        self.play(self.camera.frame.animate.scale(0.8).move_to([20,12,0]))
        text10 = Tex(
                    r"\text{硬算}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle2,UP,buff=1)
        self.play(Write(text10))
        text11 = Tex(
                    r"\text{轮换对称性}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle2,UP,buff=1)
        self.play(
            ReplacementTransform(text10,text11)
        )

        self.play(Restore(self.camera.frame))
        #大框框闪动
        rectangle9=Rectangle(color=BLUE,fill_opacity=0.0,width=90,height=8
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle9.move_to([0, -3, 0])
        self.play(Create(rectangle9))
        self.play(FadeOut(rectangle9))
        #大框框闪动
        rectangle10=Rectangle(color=BLUE,fill_opacity=0.0,width=90,height=8
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle10.move_to([0, -17, 0])
        self.play(Create(rectangle10))
        self.play(FadeOut(rectangle10))
        self.play(self.camera.frame.animate.scale(0.8).move_to([-30,-3,0]))
        text12 = Tex(
                    r"\text{硬算}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle3,UP,buff=1)
        self.play(Write(text12))
        self.play(self.camera.frame.animate.scale(0.8).move_to([0,-3,0]))
        text13 = Tex(
                    r"\text{硬算}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,UP,buff=1)
        self.play(Write(text13))
        self.play(self.camera.frame.animate.scale(0.8).move_to([30,-3,0]))
        text14 = Tex(
                    r"\text{轮换对称性}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle4,UP,buff=1)
        self.play(Write(text14))
        self.play(Restore(self.camera.frame))
        self.play(self.camera.frame.animate.scale(0.8).move_to([-30,-3,0]))
        text15 = Tex(
                    r"\text{硬算(先宏观后微观)}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle3,UP,buff=1)
        self.play(
            ReplacementTransform(text12,text15)
        )

        self.play(self.camera.frame.animate.scale(0.8).move_to([0,-3,0]))
        text16 = Tex(
                    r"\text{硬算(检测错误)}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle5,UP,buff=1)
        self.play(
            ReplacementTransform(text13,text16)
        )
        self.play(Restore(self.camera.frame))
        #箭头引出
        arrow2 = Arrow(start=[3,20,0],end=[3,15,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2))
        self.play(FadeOut(arrow2))
        #箭头引出
        arrow3 = Arrow(start=[-10,10,0],end=[-5,5,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        
        
        #箭头引出
        arrow4 = Arrow(start=[10,10,0],end=[5,5,0], color=GREEN
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow4),Create(arrow3))
        self.play(FadeOut(arrow4),FadeOut(arrow3))
        self.play(Create(arrow3))
        self.play(Create(arrow4))
        #大框框闪动
        rectangle11=Rectangle(color=BLUE,fill_opacity=0.0,width=90,height=27
                            ,stroke_color=PURPLE,stroke_width=20)
        rectangle11.move_to([0, 6, 0])
        self.play(Create(rectangle11))
        text17 = Tex(
                    r"\text{同构性}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,10,0])
        self.play(Write(text17))
        self.play(Restore(self.camera.frame))
        self.wait()